﻿// Decompiled with JetBrains decompiler
// Type: Netick.Unity.UnityAllocator
// Assembly: Netick.Unity, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E128C7FD-39ED-4452-86AC-6EC748457030
// Assembly location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Runtime\Netick.Unity.dll
// XML documentation location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Runtime\Netick.Unity.xml

using System.Runtime.CompilerServices;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;

#nullable disable
namespace Netick.Unity;

internal class UnityAllocator : IMemoryAllocator
{
  [MethodImpl(MethodImplOptions.AggressiveInlining)]
  public unsafe void* Malloc(long size, int alignment = 8)
  {
    return UnsafeUtility.Malloc(size, alignment, Allocator.Persistent);
  }

  [MethodImpl(MethodImplOptions.AggressiveInlining)]
  public unsafe void Free(void* ptr) => UnsafeUtility.Free(ptr, Allocator.Persistent);

  [MethodImpl(MethodImplOptions.AggressiveInlining)]
  public unsafe void Clear(void* ptr, long sizeBytes) => UnsafeUtility.MemClear(ptr, sizeBytes);

  [MethodImpl(MethodImplOptions.AggressiveInlining)]
  public unsafe void Copy(void* dest, void* source, long sizeBytes)
  {
    UnsafeUtility.MemCpy(dest, source, sizeBytes);
  }

  [MethodImpl(MethodImplOptions.AggressiveInlining)]
  public unsafe bool Cmp(void* ptr1, void* ptr2, long sizeBytes)
  {
    return UnsafeUtility.MemCmp(ptr1, ptr2, sizeBytes) == 0;
  }
}
